﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;

using SugarWebApi.Commands;

namespace SugarWebApi.Processors
{

	public class RestV2Processor : RestProcessor
	{

		#region Constructors

		public RestV2Processor(
			string url) : base(url)
		{
		}

		#endregion

		#region Fields

		private readonly SugarSoapV2.sugarsoap _soapV2 = new SugarSoapV2.sugarsoap();

		#endregion

		#region Propreties

		public override string RestEndPoint
		{
			get 
			{
				string format = (this.Url.EndsWith("/")) ? "" : this.Url + "/";
				format += "{0}service/v2/rest.php";
				return string.Format(format, this.Url);
			}
		}

		#endregion

		protected override LoginResult ProcesLoginCommand(
			LoginCommand command)
		{

			object result =
				CreateAndProcessRequest(
					new
					{
						@method = "login",
						@input_type = "json",
						@response_type = "json",
						@user_auth =
						new
						{
							@username = command.Username,
							@password = command.Password,
						}
					});

			return new LoginResult(command, true, string.Empty);
		}

		protected override GetAvailableModulesResult ProcesGetAvailableModeulsCommand(GetAvailableModulesCommand command)
		{
			throw new NotImplementedException();
		}

		protected override LogoutResult ProcesLogoutCommand(LogoutCommand command)
		{
			throw new NotImplementedException();
		}

		protected override GetModuleFieldsResult ProcesGetModuleFieldsCommand(GetModuleFieldsCommand command)
		{
			throw new NotImplementedException();
		}


		protected override GetEntryListResult ProcesGetEntryListCommand(GetEntryListCommand command)
		{
			throw new NotImplementedException();
		}

		protected override SetEntryResult ProcesSetEntryCommand(SetEntryCommand command)
		{
			throw new NotImplementedException();
		}
	}
}
